package com.ice.body.dict.controller;
import com.ice.body.dict.model.ReagentTypeModel;
import com.ice.body.dict.service.ReagentTypeService;
import io.swagger.annotations.ApiOperation;
import com.ice.base.controller.BaseController;
import com.github.pagehelper.PageHelper;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2021-06-30
 * Time: 09:24
 */
@RestController
@ApiIgnore(value = "字典-试剂类别")
public class ReagentTypeController extends BaseController{
    //---------------------------字典-试剂类别-----------------------start
    @Resource
    private ReagentTypeService reagentTypeService;
    
    @ApiOperation(value = "字典-试剂类别-新增")
    @PostMapping("/api/ReagentType/insert")
    public AjaxResult<ReagentTypeModel> insert_ReagentType(ReagentTypeModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            model.setCreateTime(new Date());
            reagentTypeService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "字典-试剂类别-删除")
    @PostMapping("/api/ReagentType/deleteById")
    public AjaxResult<ReagentTypeModel> deleteById_ReagentType(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count = reagentTypeService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "字典-试剂类别-更新")
    @PostMapping("/api/ReagentType/updateById")
    public AjaxResult<ReagentTypeModel> update_ReagentType(ReagentTypeModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count = reagentTypeService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "字典-试剂类别-查询一个")
    @PostMapping("/api/ReagentType/selectById")
    public AjaxResult<ReagentTypeModel> selectById_ReagentType(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           ReagentTypeModel model = reagentTypeService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "字典-试剂类别-查询多个")
    @PostMapping("/api/ReagentType/selectAll")
    public AjaxResult<ReagentTypeModel> selectList_ReagentType(ReagentTypeModel model) {
        AjaxResult r = ResponseResult.success();
        try{
           List<ReagentTypeModel> list = reagentTypeService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "字典-试剂类别-查询分页")
    @PostMapping("/api/ReagentType/selectListByPageHelper")
    public AjaxResult<ReagentTypeModel> selectListByPageHelper_ReagentType(@RequestParam(name = "pageSize") Integer pageSize,
                                                                           @RequestParam(name = "pageNum") Integer pageNum,
                                                                           ReagentTypeModel model,
                                                                           String keyWord){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           if(StringUtils.isEmpty(keyWord)) {
               list = reagentTypeService.selectListByModel(model);
           } else {
               list = reagentTypeService.selectListByKeyWord(keyWord);
           }
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------字典-试剂类别-----------------------end
}
